export interface SearchEngin {
  id: number
  name: string
  url: string
  activeUrl: string
  method?: string
  handleRequestUrl?: (query: string) => string
  handleBlankSearchUrl: (query: string) => string
}

const HEADER_SEARCH_ENGIN: SearchEngin[] = [
  {
    id: 0,
    name: '百度',
    url: new URL('@/assets/imgs/baidu.png', import.meta.url).href,
    activeUrl: 'https://www.baidu.com',
    method: 'jsonp',
    handleRequestUrl: query => {
      return `${HEADER_SEARCH_ENGIN[0].activeUrl}/sugrec?prod=pc&wd=${query}`
    },
    handleBlankSearchUrl: query => {
      return `${HEADER_SEARCH_ENGIN[0].activeUrl}/s?ie=utf-8&wd=${query}`
    }
  },
  // {
  //   id: 1,
  //   name: '开发者搜索',
  //   url: new URL('@/assets/imgs/dev.png', import.meta.url).href,
  //   activeUrl: 'https://kaifa.baidu.com',
  //   method: 'get',
  //   handleRequestUrl: query => {
  //     return `${HEADER_SEARCH_ENGIN[1].activeUrl}/rest/v1/recommend/suggests?wd=${query}`
  //   },
  //   handleBlankSearchUrl: query => {
  //     return `${HEADER_SEARCH_ENGIN[1].activeUrl}/searchPage?wd=${query}&&module=SEARCH`
  //   }
  // },
  {
    id: 2,
    name: '谷歌',
    url: new URL('@/assets/imgs/google.png', import.meta.url).href,
    activeUrl: 'https://www.google.com',
    method: 'google jsonp',
    handleRequestUrl: query => {
      return `http://suggestqueries.google.com/complete/search?q=${query}&client=gws-wiz-serp`
    },
    handleBlankSearchUrl: query => {
      return `${HEADER_SEARCH_ENGIN[1].activeUrl}/search?&q=${query}&ie=UTF-8`
    }
  },
  {
    id: 3,
    name: '掘金',
    url: new URL('@/assets/imgs/juejin.png', import.meta.url).href,
    activeUrl: 'https://www.juejin.com',
    handleBlankSearchUrl: query => {
      return `${HEADER_SEARCH_ENGIN[2].activeUrl}/search?query=${query}`
    }
  },
  {
    id: 4,
    name: 'GitHub',
    url: new URL('@/assets/imgs/github.png', import.meta.url).href,
    activeUrl: 'https://www.github.com',
    handleBlankSearchUrl: query => {
      return `${HEADER_SEARCH_ENGIN[3].activeUrl}/search?q=${query}`
    }
  }
]

export default HEADER_SEARCH_ENGIN
